package cz.acies.genea.ui.svg;

import java.io.Serializable;

import com.google.gson.JsonObject;

/**
 * 
 * 	arrow-end			string	arrowhead on the end of the path. The format for string is <type>[-<width>[-<length>]]. Possible types: classic, block, open, oval, diamond, none, width: wide, narrow, midium, length: long, short, midium.
 * 	clip-rect			string	comma or space separated values: x, y, width and height
 * 	cursor				string	CSS type of the cursor
 * 	cx					number	the x-axis coordinate of the center of the circle, or ellipse
 * 	cy					number	the y-axis coordinate of the center of the circle, or ellipse
 * 	fill				string	colour, gradient or image
 * 	fill-opacity		number
 * 	font				string
 * 	font-family			string
 * 	font-size			number	font size in pixels
 * 	font-weight			string
 * 	height				number
 * 	href				string	URL, if specified element behaves as hyperlink
 * 	opacity				number
 * 	path				string	SVG path string format
 * 	r					number	radius of the circle, ellipse or rounded corner on the rect
 * 	rx					number	horisontal radius of the ellipse
 * 	ry					number	vertical radius of the ellipse
 * 	src					string	image URL, only works for Element.image element
 * 	stroke				string 	stroke colour
 * 	stroke-dasharray	string	[“”, “-”, “.”, “-.”, “-..”, “. ”, “- ”, “--”, “- .”, “--.”, “--..”]
 * 	stroke-linecap		string 	[“butt”, “square”, “round”]
 * 	stroke-linejoin		string	[“bevel”, “round”, “miter”]
 * 	stroke-miterlimit	number
 * 	stroke-opacity		number
 * 	stroke-width		number	stroke width in pixels, default is '1'
 * 	target				string	used with href
 * 	text				string	contents of the text element. Use \n for multiline text
 * 	text-anchor			string	[“start”, “middle”, “end”], default is “middle”
 * 	title				string	will create tooltip with a given text
 * 	transform			string	see Element.transform
 * 	width				number
 * 	x					number
 * 	y					number
 * 
 * ------------------------------------------------------------------------
 * 
 * SVG example:
 * 
 * 	var shapes = paper.add([{
 * 		'type' : 'rect',
 * 		'x' : 150,
 * 		'y' : 150,
 * 		'width' : 100,
 * 		'height' : 80,
 * 		'fill' : '#759dcd',
 * 		'stroke' : '#3b5068',
 * 		'stroke-width' : 10
 * 	}]);
 * 
 */

public class G2DrawAttr implements Serializable
{
	private static final long serialVersionUID = -2093757383755742055L;
	
	protected G2Color color = new G2Color(0, 0, 0); 			// 0x000000
	protected G2Color bkColor = new G2Color(255, 255, 255); 	// 0xffffff
	
	protected int lineWidth = 1;
	protected double opacity = 1;
	
	public G2DrawAttr() {}
	

	// -----  -----------------------------------------------------------------

	public JsonObject toJSON(JsonObject element) {
		element.addProperty("stroke", 
				(getForeground() != null) ? "#" + getForeground().toHex() : null);
		element.addProperty("fill", 
			(getBackground() != null) ? "#" + getBackground().toHex() : "#0");
		element.addProperty("lineWidth", getLineWidth());
		element.addProperty("opacity", getOpacity());

		return element;
	}

	// ----- Getter and setter methods ---------------------------------------- 
	
	/**
	 * Vraci barvu pro vykresleni car 
	 * @return
	 */
	public G2Color getForeground() {
		return color;
	}

	/**
	 * Nastavi barvu pro vykresleni car
	 * @param color
	 */
	public void setForeground(G2Color color) {
		this.color = color;
	}

	/**
	 * Nastavi barvu pro vykresleni car
	 * @param color
	 * @return
	 */
	public void  setForeground(int color) {
		this.color = new G2Color(color);
	}

	/**
	 * Nastavi barvu pro vykresleni car
	 * @param red
	 * @param green
	 * @param blue
	 * @return
	 */
	public void setForeground(int red, int green, int blue) {
		this.color = new G2Color(red, green, blue);
	}

	// -----  -----------------------------------------------------------------
	
	/**
	 * Vraci barvu pro vykresleni pozadi
	 * @return
	 */
	public G2Color getBackground() {
		return bkColor;
	}

	/**
	 * Nastavi barvu pro vykresleni pozadi
	 * @param color
	 */
	public void setBackground(G2Color color) {
		this.bkColor = color;
	}

	/**
	 * Nastavi barvu pro vykresleni pozadi
	 * @param color
	 * @return
	 */
	public void setBackground(int color) {
		this.bkColor = new G2Color(color);
	}

	/**
	 * Nastavi barvu pro vykresleni pozadi
	 * @param red
	 * @param green
	 * @param blue
	 * @return
	 */
	public void setBackground(int red, int green, int blue) {
		this.bkColor = new G2Color(red, green, blue);
	}

	// -----  -----------------------------------------------------------------
	
	/**
	 * Nastavi tloustku cary
	 * @return
	 */
	public int getLineWidth() {
		return lineWidth;
	}

	/**
	 * Vraci tloustku cary
	 * @param lineWidth
	 */
	public void setLineWidth(int lineWidth) {
		this.lineWidth = lineWidth;
	}

	// -----  -----------------------------------------------------------------
	
	/**
	 * Metoda vraci pruhlednost objektu
	 * 0 = uplne pruhledny
	 * 1 = nepruhledny
	 * 
	 * @return
	 */
	public double getOpacity() {
		return opacity;
	}

	/**
	 * Metoda nastavi pruhlednost objektu pui udulosti moseOver
	 * hodnota parametru opacity je v rozsahu 0 az 1
	 * 0 = uplne pruhledny
	 * 1 = nepruhledny
	 * 
	 * @param opacity
	 */
	public void setOpacity(double opacity) {
		this.opacity = opacity;
	}

}
